import { _decorator } from "cc";
import { eventDispatcher } from "../Constants";
import { Entity } from "./Entity";
import { EventType } from "../enums/EventType";
import { DataManager } from "../manager/DataManager";
const { ccclass } = _decorator;

@ccclass("Door")
export class Door extends Entity {

    protected registerEvents(): void {
        eventDispatcher.on(EventType.ENEMY_DEATH, this.onEnemyDeath, this);
    }

    private onEnemyDeath(): void {
        if (DataManager.instance.enemies.every(enemy => enemy.state === Entity.State.DEATH)) {
            this.state = Entity.State.DEATH;
        }
    }
}